package com.bjsxt.chapter8_composit;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName Folder
 * @Description 文件夹
 * @Author 黑马程序员
 * @Date 10:43 2024/6/22
 * @Version 1.0
 **/
public class Folder implements AbstractFile{

    private String name;
    // 定义容器，用来存放本容器构件下的子节点
    private List<AbstractFile> list = new ArrayList<>();

    public Folder(String name) {
        this.name = name;
    }

    public void add(AbstractFile file){
        list.add(file);
    }

    public void remove(AbstractFile file){
        list.remove(file);
    }

    public AbstractFile getChild(int index){
        return list.get(index);
    }

    @Override
    public void killVirus() {
        System.out.println("---文件夹: " + name + ",进行查杀!");
        for (AbstractFile file : list) {
            file.killVirus();
        }
    }
}
